package com.yzy.fly.mapper;

import com.yzy.fly.entity.role.FlyComponent;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;


@Mapper
public interface FlyComponentMapper extends FlyBasicMapper<FlyComponent> {

    @Select("select * from fly_component a where 1=1") // order by seq asc
    List<FlyComponent> selectAll();

    @Select("select * from fly_component a where 1=1 and a.systemId = #{systemId}")
    List<FlyComponent> selectAllBySystemId(@Param("systemId") int systemId);

    @Select("select * from fly_component a where 1=1 and a.name = #{name}")
    FlyComponent selectOneByName(@Param("name") String name);

    /**
     * 批量插入（mysql）
     * @param entityList
     * @return
     */
    Integer insertBatchSomeColumn(Collection<FlyComponent> entityList);

    @Select("select * from fly_component a where systemId = #{systemId} order by a.packageName asc,label asc")
    List<FlyComponent> selectAllPackageNameAsc(@Param("systemId") Integer systemId);
    //TODO
//    select distinct a.packageName from fly_component a where systemId = 0 order by a.packageName asc;

    @Select("select count(1) from fly_component a where a.fileName = #{flyComponent.fileName} and a.packageName = #{flyComponent.packageName} and systemId = #{flyComponent.systemId}")
    int sameAsFileNameInPackageName(@Param("flyComponent") FlyComponent flyComponent);

    @Select("select * from fly_component a where 1=1 and a.type = #{type}")
    List<FlyComponent> selectAllByType(@Param("type") String type);
}